#include <sys/socket.h>
#include <arpa/inet.h>
#include "gaia_common.h"
#include "gaia_init_ssh2_socket.h"


int gaia_init_ssh2_socket(int *sockfd,const char *hostname,uint16_t port,struct sockaddr_in *server_addr)
{

  if( (hostname == NULL)  || (server_addr == NULL))
  {
    fprintf(stderr,"argument fail on the gaia_init_ssh2_socket!\n");
    return -1;
  }

  *sockfd = socket(AF_INET,SOCK_STREAM,0);
  server_addr->sin_family = AF_INET;
  server_addr->sin_port = htons(port);
  server_addr->sin_addr.s_addr = inet_addr(hostname);

  if(connect(*sockfd,(struct sockaddr *) server_addr,sizeof(struct sockaddr_in)) != 0)
  {
    fprintf(stderr,"failed to connect host %s\n",hostname);
    return -1;
  }

  return 0;
}
